package net.dreamlu.iot.mqtt.broker.http;

import lombok.RequiredArgsConstructor;
import net.dreamlu.iot.mqtt.broker.service.IMqttBrokerService;
import net.dreamlu.iot.mqtt.core.server.http.api.MqttHttpRoute;
import net.dreamlu.iot.mqtt.core.server.http.api.result.Result;
import net.dreamlu.iot.mqtt.core.server.http.handler.MqttHttpRoutes;
import org.springframework.stereotype.Component;
import org.tio.http.common.HttpRequest;
import org.tio.http.common.HttpResponse;

import java.util.List;

/**
 * @author: chenlf
 * @date: 2023/9/5
 * @description: EndpointsHttpApi
 **/
@Component
@RequiredArgsConstructor
public class OnlineClientsHttpApi implements MqttHttpRoute {

    private final IMqttBrokerService mqttBrokerService;

    @Override
    public String path() {
        return "/api/v1/onlineClients";
    }

    @Override
    public HttpResponse invoke(HttpRequest request) {
        List<String> onlineClients = mqttBrokerService.getOnlineClients();
        return Result.ok(request, onlineClients);
    }
}
